<?php

namespace App\Http\Repositories;

use App\Models\Comment;

class CommentRepository
{
    protected $commentModel;

    public function __construct(Comment $comment)
    {
        $this->commentModel = $comment;
    }

    public function getList($params)
    {
        return $this->commentModel->getList($params);
    }

    public function newComment()
    {
        return $this->commentModel->orderBy("updated_at", "desc")->limit(15)->get()->toArray();
    }

    public function changeEnable($id, $status)
    {
        return $this->commentModel->changeEnable($id, $status);
    }

    public function del($id)
    {
        return $this->commentModel->destroy($id);
    }

    public function getHotComments()
    {
        return $this->orderBy("view_count", "desc")->limit(config("sdblog.dashboard_num"))->get()->toArray();
    }

    public function getCommentCount()
    {
        return [
            "all_count" => $this->commentModel->count(),
            "month_count" => $this->commentModel->getMonthCount(),
        ];
    }
}